﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PloobsEngine.Publishers;

namespace PloobsEngine.IA
{
    public sealed class ActuatorsResponsesSensor : ISensor<IDictionary<String,ActuatorSensorInformation>> , IObserver
    {
        public ActuatorsResponsesSensor()
        {
            _obs = new ConcreteObserver(this);
        }

        IList<ActuatorSensorInformation> l = new List<ActuatorSensorInformation>();
        #region ISensor Members

        #region IObserver Members

        public void AddSubject(ISubject sub)
        {            
            _obs.AddSubject(sub);
        }

        public void RemoveSubject(ISubject sub)
        {
            _obs.RemoveSubject(sub);
        }

        /// <summary>
        /// Implementacao do Update, recebera a notificacao do Subject e a tratara
        /// </summary>
        /// <param name="obj"></param>
        public void Recieve(object obj)
        {
            l.Add(obj as ActuatorSensorInformation);
        }

        public void DetachFromAllSubjects()
        {
            _obs.DetachFromAllSubjects();
        }

        private IObserver _obs;
        #endregion        

        public IDictionary<String,ActuatorSensorInformation> DetectEnviroment()
        {
            Dictionary<String, ActuatorSensorInformation> dic = new Dictionary<string, ActuatorSensorInformation>();
            foreach (ActuatorSensorInformation item in l)
            {
                dic.Add(item.ActuatorName, item);
            }
            l.Clear();
            return dic;            
        }

        #endregion
    }
}
